home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 401-425 / disk_419 / yacc / src.lzh / Src / RCS / main.c,v < prev    next >
Text File  |  1990-07-14  |  8KB  |  415 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     90.07.14.21.34.24;  author loftus;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.07.14.18.55.37;  author loftus;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @Modified temporary name code to be Amiga specific.
  27. Added TmpFileName routine.
  28. @
  29. text
  30. @#include <signal.h>
  31. #include "defs.h"
  32.  
  33. char dflag;
  34. char lflag;
  35. char rflag;
  36. char tflag;
  37. char vflag;
  38.  
  39. char *file_prefix = "y";
  40. char *myname = "yacc";
  41. #ifndef AMIGA
  42. char *temp_form = "yacc.XXXXXXX";
  43. #else
  44. char *temp_form = "t:yacc";
  45. #endif
  46.  
  47. int lineno;
  48. int outline;
  49.  
  50. char *action_file_name;
  51. char *defines_file_name;
  52. char *input_file_name = "";
  53. char *output_file_name;
  54. char *text_file_name;
  55. char *union_file_name;
  56. char *verbose_file_name;
  57.  
  58. FILE *action_file;    /*  a temp file, used to save actions associated    */
  59.             /*  with rules until the parser is written        */
  60. FILE *defines_file;    /*  y.tab.h                        */
  61. FILE *input_file;    /*  the input file                    */
  62. FILE *output_file;    /*  y.tab.c                        */
  63. FILE *text_file;    /*  a temp file, used to save text until all        */
  64.             /*  symbols have been defined                */
  65. FILE *union_file;    /*  a temp file, used to save the union            */
  66.             /*  definition until all symbol have been        */
  67.             /*  defined                        */
  68. FILE *verbose_file;    /*  y.output                        */
  69.  
  70. int nitems;
  71. int nrules;
  72. int nsyms;
  73. int ntokens;
  74. int nvars;
  75.  
  76. int   start_symbol;
  77. char  **symbol_name;
  78. short *symbol_value;
  79. short *symbol_prec;
  80. char  *symbol_assoc;
  81.  
  82. short *ritem;
  83. short *rlhs;
  84. short *rrhs;
  85. short *rprec;
  86. char  *rassoc;
  87. short **derives;
  88. char *nullable;
  89.  
  90. extern char *mktemp();
  91. extern char *getenv();
  92.  
  93.  
  94. done(k)
  95. int k;
  96. {
  97.     if (action_file) { fclose(action_file); unlink(action_file_name); }
  98.     if (text_file) { fclose(text_file); unlink(text_file_name); }
  99.     if (union_file) { fclose(union_file); unlink(union_file_name); }
  100.     exit(k);
  101. }
  102.  
  103.  
  104. onintr()
  105. {
  106.     done(1);
  107. }
  108.  
  109.  
  110. set_signals()
  111. {
  112. #ifdef SIGINT
  113.     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  114.     signal(SIGINT, onintr);
  115. #endif
  116. #ifdef SIGTERM
  117.     if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
  118.     signal(SIGTERM, onintr);
  119. #endif
  120. #ifdef SIGHUP
  121.     if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
  122.     signal(SIGHUP, onintr);
  123. #endif
  124. }
  125.  
  126.  
  127. usage()
  128. {
  129.     fprintf(stderr, "usage: %s [-dlrtv] [-b file_prefix] filename\n", myname);
  130.     exit(1);
  131. }
  132.  
  133.  
  134. getargs(argc, argv)
  135. int argc;
  136. char *argv[];
  137. {
  138.     register int i;
  139.     register char *s;
  140.  
  141.     if (argc > 0) myname = argv[0];
  142.     for (i = 1; i < argc; ++i)
  143.     {
  144.     s = argv[i];
  145.     if (*s != '-') break;
  146.     switch (*++s)
  147.     {
  148.     case '\0':
  149.         input_file = stdin;
  150.         if (i + 1 < argc) usage();
  151.         return;
  152.  
  153.     case '-':
  154.         ++i;
  155.         goto no_more_options;
  156.  
  157.     case 'b':
  158.         if (*++s)
  159.          file_prefix = s;
  160.         else if (++i < argc)
  161.         file_prefix = argv[i];
  162.         else
  163.         usage();
  164.         continue;
  165.  
  166.     case 'd':
  167.         dflag = 1;
  168.         break;
  169.  
  170.     case 'l':
  171.         lflag = 1;
  172.         break;
  173.  
  174.     case 'r':
  175.         rflag = 1;
  176.         break;
  177.  
  178.     case 't':
  179.         tflag = 1;
  180.         break;
  181.  
  182.     case 'v':
  183.         vflag = 1;
  184.         break;
  185.  
  186.     default:
  187.         usage();
  188.     }
  189.  
  190.     for (;;)
  191.     {
  192.         switch (*++s)
  193.         {
  194.         case '\0':
  195.         goto end_of_option;
  196.  
  197.         case 'd':
  198.         dflag = 1;
  199.         break;
  200.  
  201.         case 'l':
  202.         lflag = 1;
  203.         break;
  204.  
  205.         case 'r':
  206.         rflag = 1;
  207.         break;
  208.  
  209.         case 't':
  210.         tflag = 1;
  211.         break;
  212.  
  213.         case 'v':
  214.         vflag = 1;
  215.         break;
  216.  
  217.         default:
  218.         usage();
  219.         }
  220.     }
  221. end_of_option:;
  222.     }
  223.  
  224. no_more_options:;
  225.     if (i + 1 != argc) usage();
  226.     input_file_name = argv[i];
  227. }
  228.  
  229.  
  230. char *
  231. allocate(n)
  232. unsigned n;
  233. {
  234.     register char *p;
  235.  
  236.     p = NULL;
  237.     if (n)
  238.     {
  239.     p = CALLOC(1, n);
  240.     if (!p) no_space();
  241.     }
  242.     return (p);
  243. }
  244.  
  245. #ifdef AMIGA
  246. char *                                                                        
  247. TmpFileName(template)                                                         
  248. char *template;                                                               
  249. {                                                                             
  250.     static char Template[256];                                                
  251.     static unsigned short Idx;                                                
  252.                                                                               
  253.     sprintf(Template, "%s%08lx.TMP", template, (long)FindTask(NULL) + Idx++);
  254.     return(Template);                                                         
  255. }
  256. #endif
  257.  
  258. create_file_names()
  259. {
  260.     int i, len;
  261.     char *tmpdir;
  262.  
  263. #ifndef AMIGA
  264.     tmpdir = getenv("TMPDIR");
  265.     if (tmpdir == 0) tmpdir = "/tmp";
  266. #else
  267.     if (tmpdir == 0) tmpdir = "t:";
  268. #endif
  269.  
  270.     len = strlen(tmpdir);
  271.     i = len + 13;
  272.  
  273. #ifndef AMIGA
  274.     if (len && tmpdir[len-1] != '/')
  275.     ++i;
  276. #endif
  277.  
  278.     action_file_name = MALLOC(i);
  279.     if (action_file_name == 0) no_space();
  280.     text_file_name = MALLOC(i);
  281.     if (text_file_name == 0) no_space();
  282.     union_file_name = MALLOC(i);
  283.     if (union_file_name == 0) no_space();
  284.  
  285.     strcpy(action_file_name, tmpdir);
  286.     strcpy(text_file_name, tmpdir);
  287.     strcpy(union_file_name, tmpdir);
  288.  
  289. #ifndef AMIGA
  290.     if (len && tmpdir[len - 1] != '/')
  291.     {
  292.     action_file_name[len] = '/';
  293.     text_file_name[len] = '/';
  294.     union_file_name[len] = '/';
  295.     ++len;
  296.     }
  297. #endif
  298.  
  299.     strcpy(action_file_name + len, temp_form);
  300.     strcpy(text_file_name + len, temp_form);
  301.     strcpy(union_file_name + len, temp_form);
  302.  
  303.     action_file_name[len + 5] = 'a';
  304.     text_file_name[len + 5] = 't';
  305.     union_file_name[len + 5] = 'u';
  306.  
  307. #ifndef AMIGA
  308.     mktemp(action_file_name);
  309.     mktemp(text_file_name);
  310.     mktemp(union_file_name);
  311. #else
  312.     strcpy(action_file_name, TmpFileName(action_file_name));
  313.     strcpy(text_file_name, TmpFileName(text_file_name));
  314.     strcpy(union_file_name, TmpFileName(union_file_name));
  315. #endif
  316.  
  317.     len = strlen(file_prefix);
  318.     if (dflag)
  319.     {
  320.     /*  the number 7 below is the size of ".tab.h"; sizeof is not used  */
  321.     /*  because of a C compiler that thinks sizeof(".tab.h") == 6        */
  322.     defines_file_name = MALLOC(len + 7);
  323.     if (defines_file_name == 0) no_space();
  324.     strcpy(defines_file_name, file_prefix);
  325.     strcpy(defines_file_name + len, DEFINES_SUFFIX);
  326.     }
  327.  
  328.     output_file_name = MALLOC(len + 7);
  329.     if (output_file_name == 0) no_space();
  330.     strcpy(output_file_name, file_prefix);
  331.     strcpy(output_file_name + len, OUTPUT_SUFFIX);
  332.  
  333.     if (vflag)
  334.     {
  335.     verbose_file_name = MALLOC(len + 8);
  336.     if (verbose_file_name == 0) no_space();
  337.     strcpy(verbose_file_name, file_prefix);
  338.     strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
  339.     }
  340. }
  341.  
  342.  
  343. open_files()
  344. {
  345.     create_file_names();
  346.  
  347.     if (input_file == 0)
  348.     {
  349.     input_file = fopen(input_file_name, "r");
  350.     if (input_file == 0) open_error(input_file_name);
  351.     }
  352.  
  353.     action_file = fopen(action_file_name, "w");
  354.     if (action_file == 0) open_error(action_file_name);
  355.  
  356.     text_file = fopen(text_file_name, "w");
  357.     if (text_file == 0) open_error(text_file_name);
  358.  
  359.     if (vflag)
  360.     {
  361.     verbose_file = fopen(verbose_file_name, "w");
  362.     if (verbose_file == 0) open_error(verbose_file_name);
  363.     }
  364.  
  365.     if (dflag)
  366.     {
  367.     defines_file = fopen(defines_file_name, "w");
  368.     if (defines_file == 0) open_error(defines_file_name);
  369.     union_file = fopen(union_file_name, "w");
  370.     if (union_file ==  0) open_error(union_file_name);
  371.     }
  372.  
  373.     output_file = fopen(output_file_name, "w");
  374.     if (output_file == 0) open_error(output_file_name);
  375. }
  376.  
  377.  
  378. int
  379. main(argc, argv)
  380. int argc;
  381. char *argv[];
  382. {
  383.     set_signals();
  384.     getargs(argc, argv);
  385.     open_files();
  386.     reader();
  387.     lr0();
  388.     lalr();
  389.     make_parser();
  390.     verbose();
  391.     output();
  392.     done(0);
  393.     /*NOTREACHED*/
  394. }
  395. @
  396.  
  397.  
  398. 1.1
  399. log
  400. @Initial revision
  401. @
  402. text
  403. @d12 1
  404. d14 3
  405. d216 12
  406. d234 1
  407. d237 3
  408. d243 2
  409. d247 1
  410. d260 1
  411. d268 1
  412. d278 1
  413. d282 5
  414. @
  415.